package com.xbongbong.paas.service.team.strategy;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.elasticsearch.util.EsHelper;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.help.BusinessUserTeamHelp;
import com.xbongbong.paas.help.FormDataHelp;
import com.xbongbong.paas.help.PaasFormHelp;
import com.xbongbong.paas.help.ProGetHelp;
import com.xbongbong.paas.help.team.FormTeamSetHelp;
import com.xbongbong.paas.help.team.TeamMessageHelper;
import com.xbongbong.paas.help.team.TeamUserHelp;
import com.xbongbong.paas.log.thread.LogThreadPoolBeanConfig;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.pojo.FormTitlePoJo;
import com.xbongbong.paas.service.ClueRuleService;
import com.xbongbong.paas.service.CustomerRuleService;
import com.xbongbong.paas.service.UserService;
import com.xbongbong.paas.service.dynamic.crm.strategy.DynamicStrategyFactory;
import com.xbongbong.paas.service.dynamic.crm.strategy.TeamDynamicStrategy;
import com.xbongbong.paas.service.team.TeamDataBusinessHelp;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.paas.util.ItemUtil;
import com.xbongbong.parent.abstracts.AbstractParentTeamStrategy;
import com.xbongbong.parent.help.CommonPermissionHelp;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.domain.entity.FormTeamSetEntity;
import com.xbongbong.pro.dynamic.pojo.dto.DynamicTeamDTO;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.TemplateErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.UserTeamErrorCodeEnum;
import com.xbongbong.pro.listbatch.pojo.TeamBatchPojo;
import com.xbongbong.pro.message.constant.CluePushConstant;
import com.xbongbong.pro.message.constant.CustomerPushConstant;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.help.PushHelper;
import com.xbongbong.pro.message.model.PushSetModel;
import com.xbongbong.pro.message.pojo.PushRefTypePojo;
import com.xbongbong.pro.message.pojo.dto.MessageRabbitMqDTO;
import com.xbongbong.pro.permission.pojo.dto.VerifyViewPermissionDTO;
import com.xbongbong.pro.rabbitmq.producer.BaseProducer;
import com.xbongbong.pro.statistic.result.pojo.ElasticAggsPojo;
import com.xbongbong.pro.team.TeamAfterFormatDTO;
import com.xbongbong.pro.team.TeamAfterModeProcessPOJO;
import com.xbongbong.pro.team.TeamAfterVerifyDTO;
import com.xbongbong.pro.team.TeamModelProcessMidPOJO;
import com.xbongbong.pro.team.TeamVerifyDTO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.ParameterConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.constant.teammembers.TeamMembersConstant;
import com.xbongbong.saas.domain.entity.ClueRuleEntity;
import com.xbongbong.saas.domain.entity.CustomerRuleEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import com.xbongbong.saas.domain.entity.ext.BomBillEntityExt;
import com.xbongbong.saas.domain.entity.ext.ClueEntityExt;
import com.xbongbong.saas.domain.entity.ext.ContractEntityExt;
import com.xbongbong.saas.domain.entity.ext.CustomerEntityExt;
import com.xbongbong.saas.domain.entity.ext.OpportunityEntityExt;
import com.xbongbong.saas.domain.entity.ext.ProductionOrderEntityExt;
import com.xbongbong.saas.domain.entity.ext.PurchaseEntityExt;
import com.xbongbong.saas.domain.entity.ext.QuotationEntityExt;
import com.xbongbong.saas.domain.entity.ext.SupplierEntityExt;
import com.xbongbong.saas.domain.entity.ext.WorkOrderEntityExt;
import com.xbongbong.saas.enums.ClueRuleEnum;
import com.xbongbong.saas.enums.CustomerRuleEnum;
import com.xbongbong.saas.enums.UserTeamEnum;
import com.xbongbong.saas.enums.UserTeamOperateTagEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.BomBillEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.MarketActivityEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.enums.business.RefundEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import com.xbongbong.saas.enums.business.SupplierContactEnum;
import com.xbongbong.saas.enums.business.SupplierEnum;
import com.xbongbong.saas.enums.business.WarehouseEnum;
import com.xbongbong.saas.enums.subform.SubFormTransferEnum;
import com.xbongbong.saas.help.PublicSeniorRuleHelp;
import com.xbongbong.saas.help.SaasGetHelp;
import com.xbongbong.saas.model.BomUserModel;
import com.xbongbong.saas.model.ClueModel;
import com.xbongbong.saas.model.CustomerModel;
import com.xbongbong.saas.model.ProductionOrderUserModel;
import com.xbongbong.saas.model.PurchaseUserModel;
import com.xbongbong.saas.model.SupplierUserModel;
import com.xbongbong.saas.model.WorkOrderExplainModel;
import com.xbongbong.saas.model.WorkOrderFormModel;
import com.xbongbong.saas.service.toolbox.help.UserTeamHelp;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.help.ProPermissionHelp;
import com.xbongbong.sys.model.UserModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;

/**
 * 团队成员抽象策略（公用模块实现放这里）
 * @author 魏荣杰
 *
 */
@Slf4j
public abstract class AbstractTeamStrategy extends AbstractParentTeamStrategy {


    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private WorkOrderExplainModel workOrderExplainModel;
    @Resource
    private BusinessUserTeamHelp businessUserTeamHelp;
    @Resource
    private UserModel userModel;
    @Resource
    private UserTeamHelp userTeamHelp;
    @Resource
    private ProGetHelp proGetHelp;
    @Resource
    private DynamicStrategyFactory dynamicStrategyFactory;
    @Resource
    private UserService userService;
    @Resource
    private CustomerRuleService customerRuleService;
    @Resource
    private ClueRuleService clueRuleService;
    @Resource
    private SaasGetHelp saasGetHelp;
    @Resource
    private BomUserModel bomUserModel;
    @Resource
    private ProductionOrderUserModel productionOrderUserModel;
    @Resource
    private PurchaseUserModel purchaseUserModel;
    @Resource
    private SupplierUserModel supplierUserModel;
    @Resource
    private PushSetModel pushSetModel;
    @Resource
    private PushHelper pushHelper;
    @Resource
    private BaseProducer baseProducer;
    @Resource
    private TeamUserHelp teamUserHelp;
    @Resource
    private FormTeamSetHelp formTeamSetHelp;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private LogThreadPoolBeanConfig logThreadPoolBeanConfig;
    @Resource
    private WorkOrderFormModel workOrderFormModel;
    @Resource
    private PublicSeniorRuleHelp publicSeniorRuleHelp;
    @Resource
    private FormDataHelp formDataHelp;
    @Resource
    private CustomerModel customerModel;
    @Resource
    private ClueModel clueModel;
    @Resource
    private EsHelper esHelper;
    @Resource
    private TeamDataBusinessHelp teamDataBusinessHelp;
    @Resource
    private TeamMessageHelper teamMessageHelper;
    @Resource
    private ProPermissionHelp proPermissionHelp;
    @Resource
    private CommonPermissionHelp commonPermissionHelp;
    @Resource
    private PaasFormHelp paasFormHelp;

    /**
     * Description: 校验团队数据
     * @param teamVerifyDTO
     * @return com.xbongbong.pro.team.TeamAfterVerifyDTO
     * @throws
     * @author 魏荣杰
     * @date 2022/1/4 15:59
     * @since
     */
    public TeamAfterVerifyDTO verifyTeam(TeamVerifyDTO teamVerifyDTO) throws XbbException {
        boolean isFormTab = teamVerifyDTO.getFromDetail();
        if (isFormTab) {
            // 从详情页tab操作过来
            return verifyFromTab(teamVerifyDTO);
        } else {
            // 从新建/编辑页过来
            return teamUserHelp.verifyFromForm(teamVerifyDTO);
        }

    }



    /**
     * Description: 校验公海池规则
     *  备注：这块校验都是原先逻辑搬过来的，很绕。dataId-type-List<userEntity>构建一个关系，然后一条数据添加多个负责人的时候可能会有多个校验规则，默认取第一个不通过的校验规则
     *  作为不通过理由。
     * @param corpid
     * @param dataIdIn
     * @param businessType
     * @param newAddMainUserMap
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2022/1/12 15:40
     * @since
     */
    public List<TeamBatchPojo> checkPublicRule(String corpid, List<Long> dataIdIn, Integer businessType, Map<String, Set<String>> newAddMainUserMap, Integer operateTag, List<TeamBatchPojo> existTeamBatchPojos,
                                               Boolean fromDetail, Boolean isNew) throws XbbException {
        int dataIdSize = CollectionsUtil.isNotEmpty(dataIdIn) ? dataIdIn.size() : BasicConstant.ZERO;
        List<Long>  existTeamBatchIdList = new ArrayList<>();
        List<Long> errorIdList = new ArrayList<>();
        if (CollectionsUtil.isNotEmpty(existTeamBatchPojos)) {
            existTeamBatchIdList = existTeamBatchPojos.stream().map(TeamBatchPojo::getDataId).collect(Collectors.toList());
        }
        List<TeamBatchPojo> teamBatchPojos = new ArrayList<>();
        if (MapUtils.isNotEmpty(newAddMainUserMap)) {
            Map<Long, Map<Integer, List<UserEntity>>> dataIdErrorMsgMap = new HashMap<>();
            for (Long dataId : dataIdIn) {
                Map<Integer, List<UserEntity>> errorMsgMap = new HashMap<>();
                Set<String> newAddMainUserList = newAddMainUserMap.get(String.valueOf(dataId));
                if (CollectionsUtil.isEmpty(newAddMainUserList)) {
                    continue;
                }
                if (Objects.equals(businessType, XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode())) {
                    List<UserEntity> userEntities = userModel.getByUserIdIn(corpid, newAddMainUserList, true);
                    Map<String, UserEntity> userEntityMap = userEntities.stream().collect(Collectors.toMap(UserEntity::getUserId, v -> v));
                    List<CustomerRuleEntity> ruleList = new ArrayList<>();
                    //公海高级模式兼容老逻辑
                    publicSeniorRuleHelp.getPublicSeniorRuleList(corpid,businessType,ruleList,new ArrayList<>());
                    for (String addUserId : newAddMainUserList) {
                        UserEntity user = userEntityMap.get(addUserId);
                        if (Objects.isNull(user)) {
                            continue;
                        }
                        try {
                            Integer type = customerRuleService.canGainCustomer(corpid, user, dataId, ruleList, dataIdSize);
                            Boolean flag = type == 0;
                            if (!flag) {
                                // 新建时不判断捞取频率规则
                                if (Objects.equals(UserTeamOperateTagEnum.DISTRIBUTION.getOperateTag(), operateTag) ||
                                        Objects.equals(UserTeamOperateTagEnum.GET_CUSTOMER.getOperateTag(), operateTag)
                                || Objects.equals(fromDetail, true) || Objects.equals(false, isNew)) {

                                }else {
                                    if (Objects.equals(type, CustomerRuleEnum.GAIN_RATE_RULE.getCode())) {
                                        continue;
                                    }
                                }
                                errorMsgMap.computeIfAbsent(type,  v -> new ArrayList<>()).add(user);
                                //TODO
                                newAddMainUserMap.remove(String.valueOf(dataId));
                                errorIdList.add(dataId);
                            }
                        } catch (Exception e) {
//                            errorMsgMap.computeIfAbsent(0,  v -> new ArrayList<>()).add(user);
                            //TODO
                            newAddMainUserMap.remove(String.valueOf(dataId));
                            errorIdList.add(dataId);
                        }
                    }
                    dataIdErrorMsgMap.put(dataId, errorMsgMap);
                } else if (Objects.equals(businessType, XbbRefTypeEnum.CLUE.getCode())) {
                    List<UserEntity> userEntities = userModel.getByUserIdIn(corpid, newAddMainUserList, true);
                    Map<String, UserEntity> userEntityMap = userEntities.stream().collect(Collectors.toMap(UserEntity::getUserId, v -> v));
                    List<ClueRuleEntity> ruleList = new ArrayList<>();
                    //公海高级模式兼容老逻辑
                    publicSeniorRuleHelp.getPublicSeniorRuleList(corpid,businessType,new ArrayList<>(),ruleList);
                    for (String addUserId : newAddMainUserList) {
                        UserEntity user = userEntityMap.get(addUserId);
                        if (Objects.isNull(user)) {
                            continue;
                        }
                        try {
                            Integer type = clueRuleService.canGainClue(corpid, user, dataId, ruleList, dataIdSize);
                            Boolean flag = type == 0;
                            if (!flag) {
                                // 新建时不判断捞取频率规则
                                if (Objects.equals(UserTeamOperateTagEnum.DISTRIBUTION.getOperateTag(), operateTag) ||
                                        Objects.equals(UserTeamOperateTagEnum.GET_CUSTOMER.getOperateTag(), operateTag) ||
                                Objects.equals(fromDetail, true) || Objects.equals(false, isNew)) {

                                }else {
                                    if (Objects.equals(type, ClueRuleEnum.GAIN_RATE_RULE.getCode())) {
                                        continue;
                                    }
                                }
                                errorMsgMap.computeIfAbsent(type,  v -> new ArrayList<>()).add(user);
                                newAddMainUserMap.remove(String.valueOf(dataId));
                                errorIdList.add(dataId);
                            }
                        } catch (Exception e) {
//                            errorMsgMap.computeIfAbsent(0,  v -> new ArrayList<>()).add(user);
                            newAddMainUserMap.remove(String.valueOf(dataId));
                            errorIdList.add(dataId);
                        }
                    }
                    dataIdErrorMsgMap.put(dataId, errorMsgMap);
                }
            }
            // 拼接错误信息，一条数据，在添加多个负责人的情况下可能被多个公海池规则给拦截，但是我们报错一条数据只会对应一个错误的公海池规则，老逻辑也是这样的
            if (MapUtils.isNotEmpty(dataIdErrorMsgMap)) {
                //少了errorName的封装，所以下面的客户和线索需要查一下业务的名称
                if (Objects.equals(businessType, XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode())) {
                    List<CustomerEntityExt> customerEntityExts = customerModel.getByKeys(dataIdIn, corpid);
                    Map<Long, CustomerEntityExt> customerMap = new HashMap<>();
                    if (CollectionsUtil.isNotEmpty(customerEntityExts)) {
                        customerMap = customerEntityExts.stream().collect(Collectors.toMap(CustomerEntityExt::getId, Function.identity()));
                    }
                    for (Map.Entry<Long, Map<Integer, List<UserEntity>>> errorEntry : dataIdErrorMsgMap.entrySet()) {
                        if (existTeamBatchIdList.contains(errorEntry.getKey())) {
                            continue;
                        }
                        Map<Integer, List<UserEntity>> errorMsgMap = errorEntry.getValue();
                        for (Map.Entry<Integer, List<UserEntity>> typeErrorMapEntry : errorMsgMap.entrySet()) {
                            Integer type = typeErrorMapEntry.getKey();
                            CustomerRuleEnum customerRuleEnum = CustomerRuleEnum.getByCode(type);
                            List<String> businessNameList = typeErrorMapEntry.getValue().stream().map(UserEntity::getName).collect(Collectors.toList());
                            TeamBatchPojo teamBatchPojo = new TeamBatchPojo();
                            teamBatchPojo.setCode(UserTeamErrorCodeEnum.API_ERROR_271021.getCode());
                            if (Objects.equals(UserTeamOperateTagEnum.ADD_TEAM_TAG.getOperateTag(), operateTag)) {
                                teamBatchPojo.setBasicOperate(UserTeamOperateTagEnum.ADD_TEAM_TAG.getName());
                            }else if (Objects.equals(UserTeamOperateTagEnum.DISTRIBUTION.getOperateTag(), operateTag)) {
                                teamBatchPojo.setBasicOperate(UserTeamOperateTagEnum.DISTRIBUTION.getName());
                            }else {
                                teamBatchPojo.setBasicOperate(UserTeamOperateTagEnum.ADD_MAIN.getName());
                            }
                            teamBatchPojo.setDataId(errorEntry.getKey());
                            teamBatchPojo.setErrorName(Objects.nonNull(customerMap) ? customerMap.get(errorEntry.getKey()).getData().get(CustomerManagementEnum.NAME.getAttr()) : null);
                            teamBatchPojo.setFailMsgReason(String.join(StringConstant.COMMA, businessNameList) +I18nMessageUtil.getMessage(I18nStringConstant.DISSATISFY) + customerRuleEnum.getName());
                            teamBatchPojos.add(teamBatchPojo);
                            break;
                        }
                    }
                }else if (Objects.equals(businessType, XbbRefTypeEnum.CLUE.getCode())) {
                    List<ClueEntityExt> clueEntityExts = clueModel.getByKeys(dataIdIn, corpid);
                    Map<Long, ClueEntityExt> clueMap = new HashMap<>();
                    if (CollectionsUtil.isNotEmpty(clueEntityExts)) {
                        clueMap = clueEntityExts.stream().collect(Collectors.toMap(ClueEntityExt::getId, Function.identity()));
                    }
                    for (Map.Entry<Long, Map<Integer, List<UserEntity>>> errorEntry : dataIdErrorMsgMap.entrySet()) {
                        Map<Integer, List<UserEntity>> errorMsgMap = errorEntry.getValue();
                        for (Map.Entry<Integer, List<UserEntity>> typeErrorMapEntry : errorMsgMap.entrySet()) {
                            Integer type = typeErrorMapEntry.getKey();
                            ClueRuleEnum clueRuleEnum = ClueRuleEnum.getByCode(type);
                            List<String> businessNameList = typeErrorMapEntry.getValue().stream().map(UserEntity::getName).collect(Collectors.toList());
                            TeamBatchPojo teamBatchPojo = new TeamBatchPojo();
                            teamBatchPojo.setCode(UserTeamErrorCodeEnum.API_ERROR_271021.getCode());
                            if (Objects.equals(UserTeamOperateTagEnum.ADD_TEAM_TAG.getOperateTag(), operateTag)) {
                                teamBatchPojo.setBasicOperate(UserTeamOperateTagEnum.ADD_TEAM_TAG.getName());
                            }else if (Objects.equals(UserTeamOperateTagEnum.DISTRIBUTION.getOperateTag(), operateTag)) {
                                teamBatchPojo.setBasicOperate(UserTeamOperateTagEnum.DISTRIBUTION.getName());
                            }else {
                                teamBatchPojo.setBasicOperate(UserTeamOperateTagEnum.ADD_MAIN.getName());
                            }
                            teamBatchPojo.setDataId(errorEntry.getKey());
                            teamBatchPojo.setErrorName(Objects.nonNull(clueMap) ? clueMap.get(errorEntry.getKey()).getData().get(ClueEnum.COMPANY_NAME.getAttr()) : null);
                            teamBatchPojo.setFailMsgReason(String.join(StringConstant.COMMA, businessNameList) +I18nMessageUtil.getMessage(I18nStringConstant.DISSATISFY) + clueRuleEnum.getName());
                            teamBatchPojos.add(teamBatchPojo);
                            break;
                        }
                    }
                }
            }
            if (CollectionsUtil.isNotEmpty(dataIdIn) && CollectionsUtil.isNotEmpty(errorIdList)) {
                dataIdIn.removeAll(errorIdList);
            }
        }
        return teamBatchPojos;
    }



    @Override
    protected BoolQueryBuilder permissionQueryIsMain(Long dataId, List<String> userIdIn, String corpid, IndexTypeEnum indexTypeEnum) {
        BoolQueryBuilder boolQueryBuilder = permissionQuery(dataId, userIdIn, corpid, indexTypeEnum);
        boolQueryBuilder.filter(termQuery(SubFormTransferEnum.getEsAttrByIndexTypeAndDbAttr(indexTypeEnum, ParameterConstant.IS_MAIN), BasicConstant.MAIN_USER));
        return boolQueryBuilder;
    }

    @Override
    protected BoolQueryBuilder permissionQuery(Long dataId, List<String> userIdIn, String corpid, IndexTypeEnum indexTypeEnum) {
        BoolQueryBuilder boolQueryBuilder = boolQuery();
        boolQueryBuilder.filter(termQuery("corpid.keyword", corpid));
        boolQueryBuilder.filter(termQuery(SubFormTransferEnum.getEsAttrByIndexTypeAndDbAttr(indexTypeEnum, FieldTypeEnum.DATAID.getAlias()), dataId));
        boolQueryBuilder.filter(termQuery("del", DelEnum.NORMAL.getDel()));
        boolQueryBuilder.filter(termsQuery(SubFormTransferEnum.getEsAttrByIndexTypeAndDbAttr(indexTypeEnum, ParameterConstant.USER_ID), userIdIn));
        return boolQueryBuilder;
    }

    /**
     * 有团队的详情权限校验
     * @param businessType
     * @return
     */
    @Override
    protected Boolean checkPermissionByTeam(Integer saasMark, Integer businessType, BoolQueryBuilder boolQueryBuilder) throws XbbException {
        if (Objects.equals(SaasMarkEnum.PAAS.getCode(), saasMark)) {
            ElasticAggsPojo elasticAggsPojo = esHelper.elasticAggs(IndexTypeEnum.IDX_FORM_DATA_TEAM, boolQueryBuilder, null);
            return StringUtil.toInt(elasticAggsPojo.getTotal(), 0) > 0;
        }
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        IndexTypeEnum indexTypeEnum;
        switch (xbbRefTypeEnum){
            case CUSTOMER_MANAGEMENT:
            case DISTRIBUTOR_MANAGEMENT:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_CUSTOMER_TEAM;
                break;
            case CONTRACT:
            case ORDER:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_CONTRACT_TEAM;
                break;
            case SALES_OPPORTUNITY:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_OPPORTUNITY_TEAM;
                break;
            case CONTACT:
            case DISTRIBUTOR_CONTACT:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_CONTACT_TEAM;
                break;
            case REFUND:
            case RETURN:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_REFUND_TEAM;
                break;
            case PAYMENT:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_PAYMENT_TEAM;
                break;
            case PAY_PLAN:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_PAY_PLAN_TEAM;
                break;
            case SUPPLIER:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_SUPPLIER_TEAM;
                break;
            case SUPPLIER_CONTACT:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_SUPPLIER_CONTACT_TEAM;
                break;
            case PURCHASE:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_PURCHASE_TEAM;
                break;
            case BOM_BILL:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_BOM_TEAM;
                break;
            case PRODUCTION_ORDER:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_PRODUCTION_ORDER_TEAM;
                break;
            case QUOTATION:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_QUOTATION_TEAM;
                break;
            case PAYMENT_SHEET:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_PAYMENT_SHEET_TEAM;
                break;
            case PAY_SHEET:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_PAYPLAN_SHEET_TEAM;
                break;
            case CLUE:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_CLUE_TEAM;
                break;
            case MARKET_ACTIVITY:
                indexTypeEnum = IndexTypeEnum.IDX_SAAS_MARKET_ACTIVITY_TEAM;
                break;
            default:
                return false;
        }
        ElasticAggsPojo elasticAggsPojo = esHelper.elasticAggs(indexTypeEnum, boolQueryBuilder, null);
        return StringUtil.toInt(elasticAggsPojo.getTotal(), 0) > 0;
    }

















    @Override
    protected FormTeamSetEntity getFormTeamSet(String corpid, Long formId, Integer saasMark, Integer businessType, Integer distributorMark) throws XbbException {
        return formTeamSetHelp.getFormTeamSet(corpid, formId, saasMark, businessType, distributorMark);
    }

    @Override
    protected TeamAfterModeProcessPOJO shareAndIsolationModeProcess(TeamModelProcessMidPOJO teamModelProcessMidPOJO) throws XbbException {
        return teamUserHelp.shareAndIsolationModeProcess(teamModelProcessMidPOJO);
    }

    @Override
    protected List<UserTeamEntity> getUserTeamList(List<Long> dataIdList, String corpid, Integer businessType, Boolean isPublic) {
        return businessUserTeamHelp.getUserTeamList(dataIdList, corpid, businessType, isPublic);
    }



    /**
     * 移交负责人进行消息推送，目前只有客户和线索两个业务；以及客户移交动态日志添加
     *
     * @param teamAfterVerifyDTO
     * @param saveName 推送的名称
     * @param paasFormDataEntity 推送的名称
     * @param originUserId 被移交用户
     * @param changeUserId 移交用户
     * @throws XbbException
     */
    @Override
    protected void changeMainPush(TeamAfterVerifyDTO teamAfterVerifyDTO, String saveName, PaasFormDataEntity paasFormDataEntity, String originUserId, String changeUserId) throws XbbException{
        String corpid = teamAfterVerifyDTO.getCorpid();
        Integer businessType = teamAfterVerifyDTO.getBusinessType();
        UserTeamEnum userTeamEnum = UserTeamEnum.getByCode(businessType);
        UserVO loginUser = teamAfterVerifyDTO.getLoginUser();
        Long handOverId = paasFormDataEntity.getId();
        List<String> pushUserList = null;
        String titleOther = null;
        String contentOther = null;
        String titleYou = null;
        String contentYou = null;
        String title = null;
        String content = null;
        PushRefTypePojo.Options options = null;
        Map<String, UserEntity> userEntityMap = new HashMap<>();
        List<UserEntity> userEntityList = userModel.getByUserId(Arrays.asList(changeUserId, originUserId), corpid);
        if (CollectionsUtil.isNotEmpty(userEntityList)) {
            userEntityMap = userEntityList.stream().collect(Collectors.toMap(UserEntity::getUserId, t -> t));
        }
        UserEntity handOverUser = userEntityMap.get(changeUserId);
        UserEntity originalUser = userEntityMap.get(originUserId);
        PushTypeEnum pushTypeEnum = null;
        switch (userTeamEnum) {
            case CUSTOMER_TEAM:
                CustomerEntityExt customerEntityExt = new CustomerEntityExt();
                BeanUtil.copyProperties(paasFormDataEntity, customerEntityExt);
                pushUserList = pushHelper.getUserIdListByPushSetRule(corpid, PushTypeEnum.CUSTOMER_HANDOVER_PUSH.getCode(), PushTypeEnum.CUSTOMER_HANDOVER_PUSH.getSubCode(), loginUser, customerEntityExt);
                options = new PushRefTypePojo.Options(paasFormDataEntity.getAppId(), paasFormDataEntity.getMenuId(), paasFormDataEntity.getFormId(), handOverId, Collections.singletonList(handOverId), SaasMarkEnum.SAAS.getCode(), businessType, XbbRefTypeEnum.CUSTOMER.getCode());
                titleOther = I18nMessageUtil.getMessage(CustomerPushConstant.CUSTOMER_HANDOVER_TO_OTHER_TITLE);
                contentOther = String.format(I18nMessageUtil.getMessage(CustomerPushConstant.CUSTOMER_HANDOVER_TO_OTHER_CONTENT), saveName, handOverUser.getName());
                titleYou = I18nMessageUtil.getMessage(CustomerPushConstant.CUSTOMER_HANDOVER_TO_YOU_TITLE);
                contentYou = String.format(I18nMessageUtil.getMessage(CustomerPushConstant.CUSTOMER_HANDOVER_TO_YOU_CONTENT), loginUser.getName(), saveName);
                title = I18nMessageUtil.getMessage(CustomerPushConstant.CUSTOMER_HANDOVER_TITLE);
                content = String.format(I18nMessageUtil.getMessage(CustomerPushConstant.CUSTOMER_HANDOVER_CONTENT), saveName, handOverUser.getName());
                pushTypeEnum = PushTypeEnum.CUSTOMER_HANDOVER_PUSH;
                break;
            case CLUE_TEAM:
                ClueEntityExt clueEntityExt = new ClueEntityExt();
                BeanUtil.copyProperties(paasFormDataEntity, clueEntityExt);
                pushUserList = pushHelper.getUserIdListByPushSetRule(corpid, PushTypeEnum.CLUE_HANDOVER_PUSH.getCode(), PushTypeEnum.CLUE_HANDOVER_PUSH.getSubCode(), loginUser, clueEntityExt);
                options = new PushRefTypePojo.Options(paasFormDataEntity.getAppId(), paasFormDataEntity.getMenuId(), paasFormDataEntity.getFormId(), handOverId, Collections.singletonList(handOverId), SaasMarkEnum.SAAS.getCode(), businessType, XbbRefTypeEnum.ALL_CLUE.getCode());
                titleOther = I18nMessageUtil.getMessage(CustomerPushConstant.CUSTOMER_HANDOVER_TO_OTHER_TITLE);
                contentOther = String.format(I18nMessageUtil.getMessage(CluePushConstant.CLUE_HANDOVER_TO_OTHER_CONTENT), saveName, handOverUser.getName());
                titleYou = I18nMessageUtil.getMessage(CluePushConstant.CLUE_HANDOVER_TO_YOU_TITLE);
                contentYou = String.format(I18nMessageUtil.getMessage(CluePushConstant.CLUE_HANDOVER_TO_YOU_CONTENT), loginUser.getName(), saveName);
                title = I18nMessageUtil.getMessage(CustomerPushConstant.CUSTOMER_HANDOVER_TITLE);
                content = String.format(I18nMessageUtil.getMessage(CluePushConstant.CLUE_HANDOVER_CONTENT), saveName, handOverUser.getName());
                pushTypeEnum = PushTypeEnum.CLUE_HANDOVER_PUSH;
                break;

        }
        //重复推送过滤
        pushUserList.removeIf(v -> Objects.equals(v, changeUserId) || Objects.equals(v, originUserId));
        MessageRabbitMqDTO messageRabbitMqToOtherDTO = new MessageRabbitMqDTO(corpid, Collections.singletonList(originUserId), Collections.singletonList(handOverId), 0, null, titleOther, contentOther, null, options);
        // 推送移交用户
        MessageRabbitMqDTO messageRabbitMqToYouDTO = new MessageRabbitMqDTO(corpid, Collections.singletonList(changeUserId), Collections.singletonList(handOverId), 0, null, titleYou, contentYou, null, options);
        // 推送消息设置的人员
        MessageRabbitMqDTO messageRabbitMqToPushSetDTO = new MessageRabbitMqDTO(corpid, pushUserList, Collections.singletonList(handOverId), 0, null, title, content, null, options);
        baseProducer.sendMessage(pushTypeEnum, messageRabbitMqToOtherDTO);
        baseProducer.sendMessage(pushTypeEnum, messageRabbitMqToYouDTO);
        baseProducer.sendMessage(pushTypeEnum, messageRabbitMqToPushSetDTO);

        // if (Objects.equals(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), businessType)) {
        //     //移交也需要在这边加项目日志
        //     String preUserNames = originalUser.getName();
        //     String communicateMemo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.CUSTOMER_TRANSFER), loginUser.getName(), preUserNames, saveName, handOverUser.getName());
        //     customerCommunicateService.addCustomerDynamic(teamAfterVerifyDTO.getCorpid(), loginUser.getUserId(), communicateMemo, handOverId, saveName, ProjectLogEnum.CUSTOMER_HANDOVER.getSubType());
        // }

    }



    /**
     *
     * @Description: 团队添加负责人/协同人推送
     * @param teamAfterVerifyDTO
     * @param isMain
     * @param saveName
     * @param addUserSet 新增负责人/新增协同人需要推送的人
     * @param paasFormDataEntity
     * @return: void
     * @Author: shen.yang
     * @Date: 2022/1/12  19:18
    */
    @Override
    protected void addUserPush(TeamAfterVerifyDTO teamAfterVerifyDTO, boolean isMain, String saveName, Set<String> addUserSet, PaasFormDataEntity paasFormDataEntity) throws XbbException {
        teamMessageHelper.addUserPush(teamAfterVerifyDTO, isMain, saveName, addUserSet, paasFormDataEntity);
    }

    /**
     *
     * @Description: 删除负责人/协同人推送
     * @param teamAfterVerifyDTO
     * @param isMain
     * @param saveName
     * @param delUserSet 需要删除的用户
     * @param paasFormDataEntity
     * @return: void
     * @Author: shen.yang
     * @Date: 2022/1/12  19:52
    */
    @Override
    protected void delUserPush(TeamAfterVerifyDTO teamAfterVerifyDTO, boolean isMain,  String saveName, Set<String> delUserSet, PaasFormDataEntity paasFormDataEntity) throws XbbException {
        teamMessageHelper.delUserPush(teamAfterVerifyDTO, isMain, saveName, delUserSet, paasFormDataEntity);


    }








    /**
     *
     * @Description: 获取团队名称，用于记录日志和推送
     * @param corpId
     * @param businessType
     * @param paasFormEntityExt 表单实体
     * @return: java.lang.String
     * @Author: shen.yang
     * @Date: 2022/1/12  15:56
     */
    @Override
    public String getSaveName(String corpId, Integer businessType, PaasFormEntityExt paasFormEntityExt, PaasFormDataEntity paasFormDataEntityExt) throws XbbException{
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        String saveName = "";
        String name;
        StringBuilder sb = new StringBuilder();
        if (paasFormDataEntityExt == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_DATA_NOT_EXIST);
        }
        JSONObject data = paasFormDataEntityExt.getData();
        String serialNo = paasFormDataEntityExt.getSerialNo();
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                saveName = FastJsonHelper.getStringOrDefaultFromFormData(data, CustomerManagementEnum.NAME.getAttr(), "");
                break;
            case SALES_OPPORTUNITY:
                name = data.getString(SalesOpportunityEnum.NAME.getAttr());
                saveName = name == null ? serialNo : sb.append(serialNo).append("（").append(name).append("）").toString();
                break;
            case CONTRACT:
                name = data.getString(ContractEnum.NAME.getAttr());
                saveName = name == null ? serialNo : sb.append(serialNo).append("（").append(name).append("）").toString();
                break;
            case CONTACT:
                saveName = FastJsonHelper.getStringOrDefaultFromFormData(data, ContactEnum.NAME.getAttr(), "");
                break;
            case SUPPLIER:
                saveName = FastJsonHelper.getStringOrDefaultFromFormData(data, SupplierEnum.SUPPLIER_NAME.getAttr(), "");
                break;
            case PURCHASE:
                name = data.getString(PurchaseEnum.PURCHASE_NAME.getAttr());
                saveName = name == null ? serialNo : sb.append(serialNo).append("（").append(name).append("）").toString();
                break;
            case PRODUCTION_ORDER:
                saveName = serialNo;
                break;
            case BOM_BILL:
                name = data.getString(BomBillEnum.NAME.getAttr());
                saveName = name == null ? serialNo : sb.append(serialNo).append("（").append(name).append("）").toString();
                break;
            case PRODUCT:
                name = data.getString(ProductEnum.NAME.getAttr());
                String productNo = FastJsonHelper.getStringOrDefaultFromFormData(data, ProductEnum.PRODUCT_NO.getAttr(), "");
                saveName = name == null ? productNo : sb.append(name).append("（").append(productNo).append("）").toString();
                break;
            case WORK_ORDER:
                saveName = serialNo;
                break;
            case REFUND:
                name = data.getString(RefundEnum.REFUND_NAME.getAttr());
                saveName = name == null ? serialNo : sb.append(serialNo).append("（").append(name).append("）").toString();
                break;
            case SUPPLIER_CONTACT:
                saveName = FastJsonHelper.getStringOrDefaultFromFormData(data, SupplierContactEnum.NAME.getAttr(), "");
                break;
            case PAYMENT:
                saveName = serialNo;
                break;
            case PAY_PLAN:
                saveName = serialNo;
                break;
            case WAREHOUSE:
                name = data.getString(WarehouseEnum.WAREHOUSE_NAME.getAttr());
                saveName = name == null ? serialNo : sb.append(serialNo).append("（").append(name).append("）").toString();
                break;
            case QUOTATION:
                saveName = serialNo;
                break;
            case CLUE:
                saveName = FastJsonHelper.getStringOrDefaultFromFormData(data, ClueEnum.COMPANY_NAME.getAttr(), "");
                break;
            case MARKET_ACTIVITY:
                saveName = FastJsonHelper.getStringOrDefaultFromFormData(data, MarketActivityEnum.NAME.getAttr(), "");
                break;
            case PAYMENT_SHEET:
            case PREPAYMENT:
            case WRITE_OFF_PREPAYMENT:
            case RED_WRITE_OFF_PREPAYMENT:
            case RED_PREPAYMENT:
            case RED_WRITE_OFF_BALANCE:
            case RED_PAYMENT_SHEET:
            case BAD_DEBT:
                saveName = paasFormDataEntityExt.getSerialNo();
                break;
            case PAY_SHEET:
            case WRITE_OFF_PREPAY:
            case PREPAY:
            case RED_WRITE_OFF_PAY:
            case RED_WRITE_OFF_PREPAY:
            case RED_PREPAY:
            case BAD_PAY:
                saveName = FastJsonHelper.getStringOrDefaultFromFormData(data, PaySheetEnum.PAY_PLAN_NO.getAttr(), "");
                break;
            case SYSTEM:
                PaasFormExplainEntity paasFormExplainEntity = paasFormExplainModel.getByFormId(paasFormEntityExt.getId(), corpId);
                List<FieldAttrEntity> explainList = JSONArray.parseArray(paasFormExplainEntity.getExplains(), FieldAttrEntity.class);
                Map<String, FieldAttrEntity> explainMap = new HashMap<>(explainList.size());
                explainList.forEach(item -> {
                    explainMap.put(item.getAttr(), item);
                });
                //paas表单标题是走表单设置那边的表单属性的数据标题字段
                PaasFormDataEntityExt paasFormDataEntityExtSen = new PaasFormDataEntityExt();
                BeanUtil.copyProperties(paasFormDataEntityExt, paasFormDataEntityExtSen);
                List<FormTitlePoJo> formTitleList = ExplainUtil.getFormTitle(JSONArray.parseArray(paasFormEntityExt.getCustomTitle()), explainMap, paasFormDataEntityExt.getData(), explainList, paasFormDataEntityExtSen);
                if(!formTitleList.isEmpty()){
                    formTitleList.forEach(titlePoJo->{
                        FieldAttrEntity fieldAttrEntity = explainMap.get(titlePoJo.getAttr());
                        if (Objects.nonNull(fieldAttrEntity) && ExplainUtil.isCombo(fieldAttrEntity.getFieldType())) {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put(titlePoJo.getAttr(), titlePoJo.getValue());
                            Object value = ItemUtil.analysisComboReturnStr(jsonObject, fieldAttrEntity);
                            titlePoJo.setValue(Collections.singletonList(value));
                        }
                    });
                    saveName = getTitle(formTitleList);
                }
                if(StringUtil.isEmpty(saveName)){
                    saveName = "--";
                }
                break;
            default:
                throw new XbbException(TemplateErrorCodeEnum.API_ERROR_350006);
        }
        return saveName;
    }

    private String getTitle(List<FormTitlePoJo> formTitleList) {
        String title = "";
        for (FormTitlePoJo item : formTitleList) {
            if (StringUtil.isEmpty(item.getAttr())) {
                title += item.getContent();
            } else {
                for (Object object : item.getValue()) {
                    title += object.toString();
                }
            }
        }
        return title;
    }

    /**
     *
     * @Description: paasFormDataEntity转换成对应的业务实体，因为push里面有强转的操作
     * @param paasFormDataEntity
     * @param businessType
     * @return: com.xbongbong.paas.domain.entity.PaasFormDataEntity
     * @Author: shen.yang
     * @Date: 2022/4/28  17:30
    */
    @Override
    protected PaasFormDataEntity entityTransfer(PaasFormDataEntity paasFormDataEntity, Integer businessType){
        UserTeamEnum userTeamEnum = UserTeamEnum.getByCode(businessType);
        switch (userTeamEnum) {
            case CUSTOMER_TEAM:
            case DISTRIBUTOR_TEAM:
                CustomerEntityExt customerEntityExt = new CustomerEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,customerEntityExt);
                return customerEntityExt;
            case ORDER_TEAM:
            case CONTRACT_TEAM:
                ContractEntityExt contractEntityExt = new ContractEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,contractEntityExt);
                return contractEntityExt;
            case OPPORTUNITY_TEAM:
                OpportunityEntityExt opportunityEntityExt = new OpportunityEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,opportunityEntityExt);
                return opportunityEntityExt;
            case SUPPLIER_TEAM:
                SupplierEntityExt supplierEntityExt = new SupplierEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,supplierEntityExt);
                return supplierEntityExt;
            case PURCHASE_TEAM:
                PurchaseEntityExt purchaseEntityExt = new PurchaseEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,purchaseEntityExt);
                return purchaseEntityExt;
            case BOMBILL_TEAM:
                BomBillEntityExt bomBillEntityExt = new BomBillEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,bomBillEntityExt);
                return bomBillEntityExt;
            case PRODUCTIONORDER_TEAM:
                ProductionOrderEntityExt productionOrderEntityExt = new ProductionOrderEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,productionOrderEntityExt);
                return productionOrderEntityExt;
            case WORK_ORDER_TEAM:
                WorkOrderEntityExt workOrderEntityExt = new WorkOrderEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,workOrderEntityExt);
                return workOrderEntityExt;
            case QUOTATION_TEAM:
                QuotationEntityExt quotationEntityExt = new QuotationEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,quotationEntityExt);
                return quotationEntityExt;
            case CLUE_TEAM:
                ClueEntityExt clueEntityExt = new ClueEntityExt();
                BeanUtils.copyProperties(paasFormDataEntity,clueEntityExt);
                return clueEntityExt;
            default:
                break;
        }
        return paasFormDataEntity;
    }


    @Override
    protected void inheritanceSave(TeamAfterVerifyDTO teamAfterVerifyDTO) throws XbbException {
        teamDataBusinessHelp.inheritanceSave(teamAfterVerifyDTO);
    }

    @Override
    protected void dynamic(TeamAfterVerifyDTO teamAfterVerifyDTO) throws XbbException {
        // 动态
        Integer businessType = teamAfterVerifyDTO.getBusinessType();
        if(Boolean.FALSE.equals(teamAfterVerifyDTO.getFromCheckRepeatForm())) {
            TeamDynamicStrategy teamDynamicStrategy = dynamicStrategyFactory.getTeamDynamicStrategyByBusinessType(businessType);
            teamDynamicStrategy.dynamic(DynamicTeamDTO.initDynamicTeamDTO(teamAfterVerifyDTO));
        }
    }

    @Override
    protected PaasFormDataEntityExt getData(String corpid, Integer businessType, Integer saasMark, Long dataId) throws XbbException{
        return formDataHelp.getFormDataWithTeam(corpid, saasMark, businessType, dataId);
    }

    @Override
    protected List<PaasFormDataEntityExt> getDataByDataIdList(Collection<Long> dataIdList, Integer businessType, Integer saasMark, Long formId, String corpid, String columns) throws XbbException {
        return formDataHelp.getByDataIdList(dataIdList, businessType, saasMark, formId ,corpid, columns);
    }
    /**
     * 由子类实现
     * @param businessType
     * @param dataIdList
     * @param corpid
     * @param nameOrSeriNoMap
     * @param saasMark
     * @return
     * @throws XbbException
     */
    @Override
    protected Map<Long, PaasFormDataEntity> getEntityMap(Integer businessType, List<Long> dataIdList, String corpid, Map<Long, String> nameOrSeriNoMap, Integer saasMark) throws XbbException {
        return userTeamHelp.getEntityMap(businessType, dataIdList, corpid, nameOrSeriNoMap, saasMark);
    }
    @Override
    protected Boolean checkPermission(PaasFormDataEntityExt paasFormDataEntityExt, Integer saasMark, UserVO loginUser, Integer businessType, Long menuId, String corpid) throws XbbException {
        VerifyViewPermissionDTO verifyViewPermissionDTO = new VerifyViewPermissionDTO(loginUser, paasFormDataEntityExt);
        return commonPermissionHelp.checkViewPermission(verifyViewPermissionDTO);
    }

    @Override
    protected List<UserTeamEntity> getUserTeamList(Collection<Long> dataIdList, String corpid, Integer businessType, Boolean isPublic, Integer isMain) {
        return userTeamHelp.getUserTeamList(dataIdList, corpid, businessType, isPublic, isMain);
    }

    @Override
    protected List<UserTeamEntity> getUserTeamListAndDel (List<Long> dataIdList, String corpid, Integer businessType, Boolean isPublic, Integer del) {
        return businessUserTeamHelp.getUserTeamList(dataIdList, corpid, businessType, isPublic, del);
    }

    @Override
    protected void apiCallBack(List<Long> dataId, Integer businessType, String corpid) {
// api回调处理
        teamDataBusinessHelp.apiCallBack(dataId, businessType, corpid);
    }

    @Override
    protected List<UserTeamEntity> getUserTeamListByParams (List<Long> dataIdList, Integer businessType, Map<String, Object> map) {
        return businessUserTeamHelp.getUserTeamListByParams(dataIdList, businessType, map);
    }




}
